package ru.ncedu.java.vlku.hrs.uil.cmd;

import ru.ncedu.java.vlku.hrs.bll.HRSManager;
import ru.ncedu.java.vlku.hrs.bll.HRSManagerFactory;
import ru.ncedu.java.vlku.hrs.model.*;

public class AddToStorage implements Command {
    // addto storage <stor_id> <cargo_id> <quantity>
    @Override
    public void execute( String[] args ) {
        if (args.length != 5)
            throw new IllegalArgumentException();
        Long stor_id = Long.parseLong(args[2]);
        Long cargo_id = Long.parseLong(args[3]);
        Long quantity = Long.parseLong(args[4]);

        HRSManager manager = HRSManagerFactory.getInstance().getHRSManager();
        Storage stor = manager.getStorageById(stor_id);
        Cargo cargo = manager.getCargoById(cargo_id);
        StorCargoAvailability sca = new StorCargoAvailability(stor, cargo, quantity);
        manager.createStorCargoAvailability(sca);
    }
}
